package circularquene;

public class MyCircularQueue {
    private int[] data;
    private int front;//当前队列的队首
    private int tail;//当前队列的队尾


    public MyCircularQueue(int k) {
        data=new int[k+1];
    }


    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        data[tail]=value;
        tail=(tail+1)%data.length;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front=(front+1)%data.length;
        return true;

    }

    public int Front() {
        if(isEmpty()) {
            return -1;
        }
            return data[front];
        }

    public int Rear() {
            if(isEmpty()){
                return -1;
            }
                int index= tail==0?  data.length-1: tail-1;
                return data[index];
        }

    public boolean isEmpty() {
        return front==tail;

    }

    public boolean isFull() {
        if((tail+1)%data.length==front){
            return true;
        }
        return false;
    }
}
